const bcrypt = require('bcrypt')
const { User } = require('../../model/user')
module.exports = async(req, res, next) => {
    const body = req.body;
    const { id } = req.query
    const user = await User.findOne({ _id: id })
    const isvalid = await bcrypt.compare(body.password, user.password)
    console.log(isvalid)
    if (isvalid) {
        await User.updateOne({ _id: id }, { username: body.username, email: body.email, role: body.role, state: body.state })
        res.redirect('/admin/user')
    } else {
        let obj = { path: '/admin/user-edit', message: '密码错误', id: id }
        next(JSON.stringify(obj))
    }

}